<template>
	<view>
		<!-- 懒加载动画 -->
		<!-- {{Number(navbarHeight) + statusBarHeight}} -->
		<view class="loading-box">
			<u-loading :show="loadingone" color="#41ADBA" size="70"></u-loading>
		</view>
		<view v-show="!loadingone">
			<view class="navbar-view">
				<dev-navbar isPageStack title="健康测评"></dev-navbar>
			</view>
			<!-- :style="{ top: Number(navbarHeight) + statusBarHeight + 'px' }" -->
			<view v-show="true" class="step-view" >
				<view class="step-left">
					当前测评：{{answerProgress.kindName}}
				</view>
				<view class="step-step">
					<view class="line-progress">
						<u-line-progress :show-percent="true" active-color="#F5A623" :percent="percentage">
						</u-line-progress>
					</view>
					<view class="">
						{{answerProgress.kindCurrentProgress}}/{{answerProgress.kindTotal}}
					</view>
				</view>
				<view class="step-right">
					{{answerProgress.totalCurrentProgress}}/{{answerProgress.askTotal}}
				</view>
			</view>
			<view>
				<view style="height: 50rpx;"></view>
				<view class="windewHeight">
					<block v-for="(item,idx) in listArr" :key="idx">
						<!-- 系统 -->
						<view class="weui-flex animationStyle" style="margin-top:91upx;"
							v-if="item.differentiate==='system'">
							<view>
								<view class="placeholder">
									<image class="serviceImg"
										src="http://static.bsyjk.cn/tx/FA0A0001B2824845B972AF7D6DC711FB.png"
										mode=""></image>
								</view>
							</view>
							<view class="weui-flex__item">
								<view class="placeholder">
									<view class="triangle">
										{{item.askName}}
										<view v-for="(titem,tidx) in item.guess" :key="tidx" class="hint"
											@click="tapHint(titem,tidx)">
											{{titem.guessQuestion}}
										</view>
									</view>
								</view>
							</view>
						</view>
						<!-- end -->
						<!-- 用户 -->
						<view class="weui-flex animationStyle" style="margin-top:91upx;"
							v-if="item.differentiate==='user'">
							<view class="weui-flex__item">
								<view class="placeholder">
									<view class="userSay" style="color: #fff;">
										{{item.askName}}
									</view>
								</view>
							</view>
							<view>
								<view class="placeholder">
									<view class="serviceImg">
										<image :src="handImg" style="width: 100%;height: 100%;" mode=""></image>
										<!-- <open-data style="width: 100%;height: 100%;" type="userAvatarUrl"></open-data> -->
									</view>
								</view>
							</view>
						</view>
						<!-- end -->
					</block>
					<view v-show="!maxtentruebr" style="height: 600upx;">
					</view>
					<view v-show="maxtentruebr" style="height: 940upx;">
					</view>
				</view>
			</view>
			<!-- 日期选择 -->
			<lb-picker ref="picker1" v-model="value1" mode="dateSelector" @change="handleChange"
				@confirm="handleConfirm" :start-date="starDate" :end-date="endTime" @cancel="handleCancel"
				:cancelView="false" :shade="false">
			</lb-picker>
			<!-- end -->
			<!-- 选择 -->
			<selecta ref="radio" :ydPopup="false" :checkedData="{}" :items="items" :mode="'radio'" :ifForm="false"
				@cancel="radioChange" @descriptionAdd="descriptionAdd"></selecta>
			<!-- 多选 -->
			<selecta ref="checkbox" :ydPopup="false" :checkedData="{}" :items="items" :mode="'checkbox'"
				:centerText="'多选'" :confirmText="'确认'" @itemsa="itemsa" @descriptionAdd="descriptionAdd"></selecta>
			<!-- end -->
			<!-- 二级联动 -->
			<lb-picker ref="picker2" v-model="value2" mode="multiSelector" :cancelText="'不知道'" :list="list2" :level="2"
				:dataset="{ name: 'label2' }" @change="handleChange" @confirm="handleConfirm" @cancel="handleCancel"
				:shade="false" :cancelView="cancelView">
			</lb-picker>
			<!-- end -->
			<!-- 选择男女 -->
			<lb-picker ref="picker3" v-model="value3" mode="selector" :list="list3" :dataset="{ name: 'label3' }"
				@change="handleChange" @confirm="handleConfirm" @cancel="handleCancel" :shade="false"
				:cancelView="false">
			</lb-picker>
			<!-- end -->
			<lb-picker ref="picker4" v-model="value4" mode="unlinkedSelector" :cancelText="'不知道'" :list="list4"
				:dataset="{ name: 'label4' }" @change="handleChange" @confirm="handleConfirmS" @cancel="handleCancel"
				:shade="false" :cancelView="cancelView">
			</lb-picker>
			<view v-if="askType == 2">
				<form @submit="formSubmit">
					<view class="weui-flex transmit" :style="'bottom:'+flexBHeight+'px'"
						:class="iphonex=='iphonex'?'iphonexH':''">
						<view class="weui-flex__item">
							<view class="placeholder">
								<view class="weui-flex">
									<view>
										<view class="placeholder" style="width: 30rpx;">
											<!-- <view class="sendAudio">
										</view> -->
										</view>
									</view>
									<view class="weui-flex__item">
										<view class="placeholder">
											<input name="userInput" v-model="chartText" @focus="autoFocus"
												@blur="btoomBlur" :adjust-position="false" class="inputSend">
										</view>
									</view>
								</view>
							</view>
						</view>
						<view class="weui-flex__item">
							<view>
								<button class="sendBtn" form-type="submit">发送</button>
							</view>
						</view>
					</view>
				</form>
			</view>
		</view>
	</view>
</template>
<script>

	// 获取系统状态栏的高度
	let systemInfo = uni.getSystemInfoSync();
	let menuButtonInfo = {};
	// 如果是小程序，获取右上角胶囊的尺寸信息，避免导航栏右侧内容与胶囊重叠(支付宝小程序非本API，尚未兼容)
	// #ifdef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO || MP-QQ
	menuButtonInfo = uni.getMenuButtonBoundingClientRect();
	// #endif
	function userAnswerDetail(t) {
		if (t.ansValueV == '重新开始 ') { //重新开始
			t.listArr.push({
				differentiate: 'user',
				askName: t.ansValueV
			});
			t.makeNewAnswerRecord(t.topicId) //生产新的用户评测记录
			t.getAskAndReply() //开始进行专题健康评测
		} else if (t.ansValueV == '继续 ') { //继续
			t.listArr.push({
				differentiate: 'user',
				askName: t.ansValueV
			});
			let askAnsRecordVOList = t.askAnsRecordVOList;
			for (let i = 0; i < askAnsRecordVOList.length; i++) {
				let unitName = askAnsRecordVOList[i].unitName == null ? '' : askAnsRecordVOList[i].unitName
				t.listArr.push({ //添加系统
					differentiate: 'system',
					askName: askAnsRecordVOList[i].askName,
				});
				t.listArr.push({ //添加用户
					differentiate: 'user',
					askName: askAnsRecordVOList[i].answers + unitName,
				});

			}
			t.listArr.push(t.ask)
			let resdata = {
				result: t.continueAsk
			}
			t.judge(resdata, t)

		} else {
			t.controlHeight = 0
			t.listArr.push({
				differentiate: 'user',
				askName: t.askType == 4 ? t.ansValue4 : t.ansValue,
			});
			let ansValue = t.ansValue;
			t.$api.post(global.apiUrls.userAnswerDetail, {
				ansValue: t.ansValueV,
				userAnsId: t.userAnsId,
				userId: t.userId,
				topicId: t.topicId,
				askId: t.askId,
				ansId: t.ansId //askKind
			}).then(res => {
				if (res.data.result !== null) { //判断最后null
					let answerProgress = res.data.result.answerProgress;
					if(res.data.result.answerProgress == null||!res.data.result.answerProgress){
						t.answerProgress.totalCurrentProgress = 1
					}
					if (res.data.result.answerProgress) {
						t.percentage = t.toPercent(answerProgress.kindCurrentProgress, answerProgress.kindTotal)
						answerProgress.totalCurrentProgress = answerProgress.askTotal - answerProgress
							.totalCurrentProgress + 1
						t.answerProgress = answerProgress
					}
					if (res.data.result.answers.length == 1) { //只有一个选择情况
						t.ansId = res.data.result.answers[0].ansId; //题型id
						t.askId = res.data.result.answers[0].askId
					}
					res.data.result.ask.differentiate = 'system'; //区分添加系统
					res.data.result.ask.guess = res.data.result.guess
					if (res.data.result.robotAnswers != null) { //机器人回答
						for (let i = 0; i < res.data.result.robotAnswers.length; i++) {
							t.listArr.push({
								differentiate: 'system',
								askName: res.data.result.robotAnswers[i].ansContent
							});
						}
					}
					t.listArr.push(res.data.result.ask);
				}
				if (res.data.code == 2501) { //问答结束
					// console.log('1600000000000000西行了', res.data.code, res.data.result)
					t.makeReport() //调用生成报告
				} else {
					t.judge(res.data, t)
				}
			}).catch(err => {

			})
		}

	}

	import selecta from '@/pages/subpackage/components/lb-picker/select'
	import lbPicker  from '@/pages/subpackage/components/lb-picker/index';
	import uLoading from "@/uview-ui/components/u-loading/u-loading.vue"

import uLineProgress from "@/uview-ui/components/u-line-progress/u-line-progress.vue"
	export default {
		components: {
			uLoading,
			uLineProgress,
			lbPicker,
			selecta
		},
		data() {
			return {
				percentage: 0, //百分比
				menuButtonInfo: menuButtonInfo, //导航栏高
				statusBarHeight: systemInfo.statusBarHeight, //导航栏高
				answerProgress: {
					askTotal: '',
					kindCurrentProgress: '',
					kindName: '',
					kindTotal: '',
					topicName: '',
					totalCurrentProgress: '',
				}, //答题进度
				chartText: '',
				flexBHeight: 0,
				cancelView: false, //是否显示不知道
				maxtentruebr: false,
				iphonex: '', //是否苹果x以上机型
				value4: ['', '0', ''], //默认值
				list4: [], //带小数点
				phone: '', //手机号
				storeId: '', //门店测评id
				starDate: '1900-12-31', //开始时间
				endTime: this.$basejs.thisdayFormat2(false), //结束时间默认今天
				loadingone: false,
				componentKey: 0,
				// checkedData:[],
				guess: [],
				controlHeight: 0,
				scrollTop: 0,
				style: {
					pageHeight: '',
					contentViewHeight: ''
				},
				ansValue: '',
				ansValue4: '',
				userAnsId: '',
				userId: '',
				topicId: '',
				askId: '',
				ansId: '', //askKind
				// answersArr:[],//回复答案存储
				askType: '', //显示工具
				value1: '1980-01-01', //默认选中生日
				value2: [],
				value3: '',
				label2: '',
				label3: '',
				list2: [],
				list3: [],
				listArr: [
					// {
					// 	differentiate:'system',
					// 	askName:'您怎么称呼',
					// 	guess:['小张','小王','小李']
					// }
				],
				result: '',
				genderup: true,
				items: [],
				stepId: '',
				task: '', //任务
				upPage: '', //任务来源页面
				handImg: '', //头像
			}
		},
		computed: {
			// 导航栏内部盒子的样式
			navbarInnerStyle() {
				let style = {};
				// 导航栏宽度，如果在小程序下，导航栏宽度为胶囊的左边到屏幕左边的距离
				style.height = this.navbarHeight + 'px';
				// // 如果是各家小程序，导航栏内部的宽度需要减少右边胶囊的宽度
				// #ifdef MP
				let rightButtonWidth = systemInfo.windowWidth - menuButtonInfo.left;
				style.marginRight = rightButtonWidth + 'px';
				// #endif
				return style;
			},
			// 整个导航栏的样式
			navbarStyle() {
				let style = {};
				style.zIndex = this.zIndex ? this.zIndex : this.$u.zIndex.navbar;
				// 合并用户传递的背景色对象
				Object.assign(style, this.background);
				return style;
			},
			// 导航中间的标题的样式
			titleStyle() {
				let style = {};
				// #ifndef MP
				style.left = (systemInfo.windowWidth - uni.upx2px(this.titleWidth)) / 2 + 'px';
				style.right = (systemInfo.windowWidth - uni.upx2px(this.titleWidth)) / 2 + 'px';
				// #endif
				// #ifdef MP
				// 此处是为了让标题显示区域即使在小程序有右侧胶囊的情况下也能处于屏幕的中间，是通过绝对定位实现的
				let rightButtonWidth = systemInfo.windowWidth - menuButtonInfo.left;
				style.left = (systemInfo.windowWidth - uni.upx2px(this.titleWidth)) / 2 + 'px';
				style.right = rightButtonWidth - (systemInfo.windowWidth - uni.upx2px(this.titleWidth)) / 2 +
					rightButtonWidth +
					'px';
				// #endif
				style.width = uni.upx2px(this.titleWidth) + 'px';
				return style;
			},
			// 转换字符数值为真正的数值
			navbarHeight() {
				// #ifdef APP-PLUS || H5
				return this.height ? this.height : 44;
				// #endif
			}
		},
		onLoad(e) {
			console.log(e, '33333331111111111');
			// if(e.userAnsId){
			// 	this.userAnsId = e.userAnsId
			// }
			if(!global.token){
				this.$urouter.redirectTo({
					url: '/pages/signIn/signIn',
					params: {
						jumpInterface:'/pages/subpackage/home/oneAccess/evaluating',
						transferParameters:JSON.stringify(e)
					}
				});
				return
			}
			if(e.scene){
				let scene = decodeURIComponent(e.scene);
				let splitParameters =scene.split(',');
                e.storeId = splitParameters[0];
				uni.setStorageSync('storeId', splitParameters[0])
			}
			if (e.storeId) {
				uni.setStorageSync('storeId', e.storeId)
                this.storeId = e.storeId //门店id
			} else if (e.signIn == '1') { //从登陆页面来
				e.storeId = uni.getStorageSync('storeId')
                this.storeId = e.storeId //门店id
			}
			this.iphonex = uni.getStorageSync('iphonex')
			// 检测登录
			this.$basejs.globaltoken()
			// end
			// 门店测评id
			if (e.storeId) {
				e.topicId = 2
			}
			   console.info(e.topicId,"e.storeId222--->")
			this.phone = uni.getStorageSync(global.IS_DEV?'USER_DATA_BSY_T':'USER_DATA_BSY_Z').phone //静态手机号


			this.handImg = global.userInfo.avatarUrl;
			this.upPage = e.page ? e.page : '';

			if (e.task) {
				this.task = e.task; //任务1 等于完成任务
			}
			if (e.stepId) {
				this.stepId = e.stepId; //stepId任务ID
			}

			// const res = uni.getSystemInfoSync();
			// this.style.pageHeight = res.windowHeight;
			// this.style.contentViewHeight = res.windowHeight - uni.getSystemInfoSync().screenWidth / 750 * (100); //像素
			// this.userId = new Date().getTime();
			this.userId = e.userId ? e.userId : uni.getStorageSync(global.IS_DEV?'USER_DATA_BSY_T':'USER_DATA_BSY_Z').userId; //用户id
			this.topicId = e.topicId ? e.topicId : 3; //3用户端只能问答
			let t = this;
			t.loadingone = true;
			if (e.pageMy == '1') { //来自我的从新评测
				this.makeNewAnswerRecord(this.topicId) //生产新的用户评测记录
				this.getAskAndReply() //开始进行专题健康评测
			} else { //来自首页
				this.waitHistory() //获取当前评测记录
			}
			uni.$on('radioChange', this.radioChange)
			// this.$api.post(global.apiUrls.makeNewAnswerRecord, {
			// 	userId: t.userId,
			// 	topicId: t.topicId,
			// 	phone: ''
			// }).then(res => {
			// 	t.userAnsId = res.data.result.userAnsId;
			// 	t.result = res.data.result
			// 	t.loadingone = false;
			// }).catch(err => {

			// })

		},
		onUnload(e) { //页面删除
			uni.$off('radioChange', this.radioChange)
		},
		methods: {
			// 获取百分比
			toPercent(num, total) {
				console.log((Math.round(num / total * 10000) / 100.00), '417777777777777777')
				return (Math.round(num / total * 10000) / 100.00); // 小数点后两位百分比
			},
			btoomBlur() {
				this.flexBHeight = 0
			},
			autoFocus(e) {
				console.log(e, '319')
				this.flexBHeight = e.detail.height
			},
			toHourMinute(minutes) {
				return {
					h: Math.floor(minutes / 60),
					s: minutes % 60
				}
			},
			judge(data, t) {
				t.cancelView = false
				console.log(data, 174)
				let askType = data.result.ask.askType,
					answers = data.result.answers,
					answersArr = t.answersArr,
					thislist = [];
				console.log(data.result, 188888)
				t.guess = data.result.guess;
				t.askName = data.result.ask.askName;
				t.askAnswers = data.result.answers;
				t.askType = data.result.ask.askType;
				t.askId = data.result.ask.askId;
				t.askType = askType;

				let thislistNum = 1, //索引
					defaultValue = data.result.answers[0].defaultValue ? data.result.answers[0].defaultValue : ''; //回调默认值
				t.maxtentruebr = false; //高度100盒子
				if (askType == 1) { //级联2
					if (t.askName == '你通常每天有多少时间坐着或靠着？') {

						t.ansId = data.result.answers[0].ansId;
						let oneArr = [],
							threeArr = [];
						for (let i = 0; i < 24; i++) {
							oneArr.push(i)
						}
						for (let i = 0; i < 60; i++) {
							threeArr.push(i)
						}
						t.list4 = [oneArr, ['小时'], threeArr, ['分']];
						let htime = t.toHourMinute(defaultValue)
						t.value4 = [htime.h, '小时', htime.s, '分']
						t.$refs['picker4'].show()
					} else {
						let unit = data.result.ask.unitName,
							valueExpression = data.result.ask.valueExpression,
							unitName = data.result.ask.unitName,
							askRequire = data.result.ask.askRequire;
						if (askRequire == 1) {
							t.cancelView = true
						}
						let str = valueExpression;
						console.log(askRequire,valueExpression, data,'32555555555555555555555555555')
						let strIndex = str.indexOf("."), //.的索引
							gangIdex = str.indexOf("|") //|的索引
						if (str.startsWith('|', gangIdex)) {
							let qgArr = str.split('|'),
								xsList = []
							t.list4 = []; //赋空
							console.log(qgArr, 490000000000)
							for (let i = 0; i < qgArr.length; i++) { //执行3次
								qgArr[i] = qgArr[i].replace(".", "-");
								qgArr[i] = qgArr[i].split("-");
								console.log(qgArr, 4944)
								for (let j = 0; j < qgArr[i].length; j++) {
									if (j == 0 || j == 2) {
										qgArr[i][j] = qgArr[i][j].replace('(', '') * 1;
										xsList.push(qgArr[i][j])
									} else {
										qgArr[i][j] = parseFloat(qgArr[i][j])
										xsList.push(qgArr[i][j])
									}
								}
							}
							console.log(xsList, 500000333333)
							for (let i = 0; i < xsList.length; i++) {
								if (i % 2 == 0) {
									let upArr = []
									for (let j = xsList[i]; j < xsList[i + 1]; j++) {
										upArr.push({
											label: i == 2 || i == 6 ? '.' + j : '' + j,
											value: '' + j,
											children: [{
												label: unit,
												ansId: answers[0].ansId,
												askId: answers[0].askId,
												value: '',
											}]
										})
									}
									t.list4.push(upArr)
									if (t.list4.length == 2 || t.list4.length == 5) {
										t.list4.push([{
											label: unit,
											value: unit,
										}])
									}

								}
							}
							setTimeout(() => {
								t.$refs['picker4'].show()
							}, 500);
						} else if (str.startsWith('.', strIndex)) {
							console.log('包含点。。。。。')
							// 包含
							for (let i = 0; i < 3; i++) { //执行3次
								str = str.replace(".", "-");
								defaultValue = defaultValue.replace(".", "-")
							}
							defaultValue = defaultValue.split('-')
							// 小数点回显需要的值分割获取
							let defaultValue0 = defaultValue[0] ? defaultValue[0] : '0',
								defaultValue1 = defaultValue[1] ? defaultValue[1] : '0',
								defaultValue2 = defaultValue[2] ? defaultValue[2] : '0',
								defaultValue3 = defaultValue[3] ? defaultValue[3] : '0';
							// end
							let strNumber = str.split('-'),
								listArr = []
							for (let i = 0; i < strNumber.length; i++) {
								console.log(strNumber[i], i, '34666666666')
								if (i == 0 || i == 2 || i == 4 || i == 6) {
									listArr.push(strNumber[i].replace('(', '') * 1)
								} else {
									listArr.push(parseFloat(strNumber[i]))
								}
							}
							let oneArr = [], //整数
								twoArr = [], //小数
								unitArr = []; //单位
							for (let i = listArr[0]; i < listArr[1]; i++) {
								oneArr.push({
									label: '' + i,
									value: '' + i,
									children: [{
										label: unit,
										ansId: answers[0].ansId,
										askId: answers[0].askId,
										value: '',
									}]
								})
							}
							for (let i = listArr[2]; i < listArr[3]; i++) {
								twoArr.push({
									label: '.' + i,
									value: '.' + i,
									children: [{
										label: unit,
										ansId: answers[0].ansId,
										askId: answers[0].askId,
										value: '',
									}]
								})
							}
							console.log(listArr.length, defaultValue0, defaultValue1, '398888888')
							if (listArr.length == 4) { //两位小数
								t.list4 = [oneArr, twoArr, [{
									label: unit,
									value: unit,
								}]];
								t.value4 = [defaultValue0, '.' + defaultValue1, unit]
							} else if (listArr.length == 6) { //三位小数
								let threeArr = []
								for (let i = listArr[4]; i < listArr[5]; i++) {
									threeArr.push({
										label: '' + i,
										value: '' + i,
										children: [{
											label: unit,
											ansId: answers[0].ansId,
											askId: answers[0].askId,
											value: '',
										}]
									})
								}
								t.list4 = [oneArr, twoArr, threeArr, [{
									label: unit,
									value: unit,
								}]];
								t.value4 = [defaultValue0, '.' + defaultValue1, '' + defaultValue2, unit]
							} else if (listArr.length == 8) { //四位小数
								let fourArr = [],
									threeArr = [];
								for (let i = listArr[4]; i < listArr[5]; i++) {
									threeArr.push({
										label: '' + i,
										value: '' + i,
										children: [{
											label: unit,
											ansId: answers[0].ansId,
											askId: answers[0].askId,
											value: '',
										}]
									})
								}
								for (let i = listArr[6]; i < listArr[7]; i++) {
									fourArr.push({
										label: '' + i,
										value: '' + i,
										children: [{
											label: unit,
											ansId: answers[0].ansId,
											askId: answers[0].askId,
											value: '',
										}]
									})
								}
								t.list4 = [oneArr, twoArr, threeArr, fourArr, [{
									label: unit,
									value: unit,
								}]];
								t.value4 = [defaultValue0, '.' + defaultValue1, '' + defaultValue2, '' + defaultValue3,
									unit
								]
							}

							setTimeout(() => {
								t.$refs['picker4'].show()
							}, 500);
						} else {
							let num1 = parseFloat(str.split('-')[0].replace('(', '')),
								num2 = parseFloat(str.split('-')[1]);
							console.log(str, num1, num2, '3277777777777777')
							if (unit == null) {
								unit = ''
							}
							if (num2 > 1000) { //循环大于1000
								for (let i = num1 + 100; i < num2; i += 100) {
									console.log(i, 196)
									if (i == defaultValue) { //获取索引
										thislistNum = i * 0.01
									}
									if (unit == '支' || unit == '年' || unit == '天' || unit == '分钟' || unit == '分') {
										thislist.push({
											label: i,
											value: i,
											children: [{
												label: unit,
												ansId: answers[0].ansId,
												askId: answers[0].askId,
												value: '',
											}]
										})
									} else { //身高单位
										thislist.push({
											label: i,
											value: i,
											children: [{
												label: unit,
												ansId: answers[0].ansId,
												askId: answers[0].askId,
												value: 0,
											}]
										})
									}

								}
							} else {
								console.log(num1, num2, '491111111')
								for (let i = num1 + 1; i < num2; i++) {
									if (i == defaultValue) { //获取索引
										thislistNum = i
									}
									if (unit == '支' || unit == '年' || unit == '天' || unit == '分钟' || unit == '分') {
										thislist.push({
											label: i,
											value: i,
											children: [{
												label: unit,
												ansId: answers[0].ansId,
												askId: answers[0].askId,
												value: '',
											}]
										})
									} else { //身高单位
										thislist.push({
											label: i,
											value: i,
											children: [{
												label: unit,
												ansId: answers[0].ansId,
												askId: answers[0].askId,
												value: 0,
											}]
										})
									}

								}
							}
							t.list2 = thislist;
							if (num1 >= 1) { //num大于1的情况
								if (thislistNum - num1 >= 1) {
									thislistNum = thislistNum - num1
								}
							}
							console.log(thislist, thislistNum, num1, '59111111111')
							if (thislist.length > 1) {
								t.value2 = [thislist[thislistNum - 1].value, thislist[thislistNum - 1].children[0]
									.label
								] //当前值 -1 等于索引
							}
							setTimeout(() => {
								t.$refs['picker2'].show()
							}, 500);
						}
						console.log('545')
					}

				} else if (askType == 2) { //手动输入
					t.ansId = data.result.answers[0].ansId
					t.chartText = data.result.answers[0].defaultValue
				} else if (askType == 3) { //单选
					t.$refs['radio'].show()
					console.log(answers,defaultValue, '60888888888888888')
					for (let i = 0; i < answers.length; i++) {
						answers[i].label = answers[i].ansName
						answers[i].value = answers[i].ansName
						thislist.push(answers[i])
					}
					console.log(thislist, '2666')
					t.items = thislist
					t.value3 = defaultValue
				} else if (askType == 4) { //多选
					for (let i = 0; i < answers.length; i++) {
						answers[i].label = answers[i].ansName;
						answers[i].value = answers[i].ansName;
						// 多选选中
						if (answers[i].defaultValue) {
							answers[i].checked = true
						} else {
							answers[i].checked = false
						}
						thislist.push(answers[i])
					}
					// t.$refs['checkbox'].checkboxChange()
					t.items = thislist;
					if (thislist.length > 7) {
						t.$refs['checkbox'].maxtentrue()
						t.maxtentruebr = true; //高度100盒子
					} else {
						t.$refs['checkbox'].show()
					}
				} else if (askType == 5) { //生日输入
					t.ansId = data.result.answers[0].ansId; //生日 ansId
					let defaultValue = data.result.answers ? data.result.answers[0].defaultValue : ''; //默认时间
					if (defaultValue && defaultValue != '') {
						t.value1 = defaultValue
					}
					t.$refs['picker1'].show();
					for (let i = 0; i < answers.length; i++) {
						answersArr.push(answers[i])
					}
					// t.ansId = answers[0].ansId
				}
				setTimeout(() => {
					uni.pageScrollTo({
						scrollTop: 99999999999,
						duration: 0
					});
				}, 200)
			},
			waitHistory() { //获取评测历史
				let _this = this;
				this.$api.get(global.apiUrls.waitHistory, {
					// 传入参数
					userId: this.userId,
					topicId: this.topicId,
					phone: this.phone,
                    storeId:this.storeId
				}).then(res => {
					if (res.data.code == 2502) { //没有历史评测
						_this.listArr.push({ //添加系统
							differentiate: 'system',
							askName: 'Hi，我是您的健康小助手，先让我们来了解下您的健康情况吧！',
						});
						setTimeout(() => {
							_this.makeNewAnswerRecord(this.topicId) //生产新的用户评测记录
							_this.getAskAndReply() //开始进行专题健康评测
						}, 1000)
					} else { //有历史评测
						let answerProgress = res.data.result.answerProgress;
						if (res.data.result.answerProgress) {
							_this.percentage = _this.toPercent(answerProgress.kindCurrentProgress, answerProgress
								.kindTotal)
							answerProgress.totalCurrentProgress = answerProgress.askTotal - answerProgress
								.totalCurrentProgress + 1
							_this.answerProgress = answerProgress
						}
						_this.listArr.push({ //添加系统
							differentiate: 'system',
							askName: '嗨，又见面了，您是想继续上次评估呢？还是重新开始呢？',
						});
						_this.$refs['radio'].show()
						_this.items = [{
								label: '重新开始 ',
								value: '重新开始 '
							},
							{
								label: '继续 ',
								value: '继续 '
							}
						]
						let askAnsRecordVOList = res.data.result.askAnsRecordVOList;
						_this.askAnsRecordVOList = askAnsRecordVOList

						_this.userAnsId = res.data.result.userAnsId;


						_this.continueAsk = res.data.result.continueAsk
						res.data.result.continueAsk.ask.differentiate = 'system'; //区分添加系统
						_this.ask = res.data.result.continueAsk.ask

					}
					_this.loadingone = false; //关闭加载
				})
			},
			// 开始进行专题健康评测
			getAskAndReply() {
				let _this = this;
				this.$api.post(global.apiUrls.getAskAndReply, {
					// 传入参数
					userId: this.userId,
					topicId: this.topicId,
					phone: this.phone
				}).then(res => {
					console.log(res, '7100000000')
					_this.ansValue = ''
					_this.ansRadio = 0
					_this.ansChecks = []
					_this.askName = res.data.result.ask.askName
					_this.askAnswers = res.data.result.answers
					_this.askType = res.data.result.ask.askType
					_this.askId = res.data.result.ask.askId;
					if (res.data.result.answerProgress) {
						let answerProgress = res.data.result.answerProgress;
						answerProgress.totalCurrentProgress = answerProgress.totalCurrentProgress = answerProgress.askTotal - answerProgress
							.totalCurrentProgress + 1
						_this.percentage = _this.toPercent(answerProgress.kindCurrentProgress, answerProgress
							.kindTotal)
						_this.answerProgress = answerProgress
					}
					if (_this.askType == 2) { //输入框类型 、2+1
						_this.ansId = _this.askAnswers[0].ansId
						_this.chartText = res.data.result.answers[0].defaultValue

					} else { //其他类型 、中医
						_this.judge(res.data, _this)
					}
					res.data.result.ask.differentiate = 'system'; //区分添加系统
					_this.listArr.push(res.data.result.ask)
				})
			},
			makeNewAnswerRecord(topicId) {
				let fdata = {
					topicId: topicId,
					userId: uni.getStorageSync(global.IS_DEV?'USER_DATA_BSY_T':'USER_DATA_BSY_Z').userId,
					phone: this.phone,
                    storeId:this.storeId
				}
				let _this = this;
				this.$api.post(global.apiUrls.makeNewAnswerRecord, fdata)
					.then(res => {
						if (res.data.code == 1000) {
							_this.userAnsId = res.data.result.userAnsId;
							_this.result = res.data.result
							_this.loadingone = false;
						}
					})
			},
			// 监听选择
			radioChange(e) {
				let _this = this;
				_this.ansId = e.ansId;
				_this.askId = e.askId;
				_this.ansValue = e.ansValue;
				_this.ansValue4 = e.ansValue4 ? e.ansValue4 : ''
				_this.ansValueV = e.ansValue;
				userAnswerDetail(_this)
			},
			// 获取用户评测记录详细信息
			userAnswer() {
				let _this = this;
				this.$api.get(global.apiUrls.userAnswer + '/' + uni.getStorageSync(global.IS_DEV?'USER_DATA_BSY_T':'USER_DATA_BSY_Z').userId + '/' + _this
						.userAnsId, {
							phone: this.phone
						})
					.then(res => {
						if (res.data.code == 1000) {
							if (_this.task == '0' && _this.upPage == '') { //完成添加计划任务
								_this.userTaskStep(_this.stepId)
							} else if (_this.task == '0' && _this.upPage == 'myschedule') { //完成健康豆计划
								_this.userPointRecord(_this.stepId)
							}
							return
						}
					}).catch(err => {})
			},
			// 评测完成生成报告
			makeReport() {
				let _this = this;
				let fdata = {
					topicId: _this.topicId,
					userAnsId: _this.userAnsId,
					userId: uni.getStorageSync(global.IS_DEV?'USER_DATA_BSY_T':'USER_DATA_BSY_Z').userId,
					phone: this.phone
				}
				// 加加载
				uni.showLoading({
					title: '报告生成中'
				});
				this.$api.post(global.apiUrls.makeReport, fdata)
					.then(res => {
						uni.hideLoading();
						if (res.data.code == 1000) {
							uni.setStorageSync('userAnsId', _this.userAnsId)
							//
							// if (_this.task == '0' && _this.upPage == '') { //完成添加计划任务
							// 	_this.userTaskStep(_this.stepId)
							// } else if (_this.task == '0' && _this.upPage == 'myschedule') { //完成健康豆计划
							// 	_this.userPointRecord(_this.stepId)
							// }
							if (_this.task == '0') { //完成健康豆计划
								_this.userPointRecord(_this.stepId)
							}
							if (_this.topicId == 4) { //中医
								uni.reLaunch({
									url: '/subpackage/TCM-Report/TCM-Report?phone=' + fdata.phone +
										'&userAnsId=' + _this
										.userAnsId
								})
							} else { //2+1
								uni.reLaunch({
									url: '/pages/subpackage/home/HealthReport/HealthReport?userAnsId=' + _this
										.userAnsId
								})
							}

						}
					}).catch(err => {
						uni.hideLoading();
					})
			},
			userPointRecord(taskStepId) { //我的页面
				let fdata = {
					userId: uni.getStorageSync(global.IS_DEV?'USER_DATA_BSY_T':'USER_DATA_BSY_Z').userId,
					pointDict: 'HEALTH_ASK',
				}
				this.$shopnew.post(global.apiUrls.userPointRecord, fdata)
					.then(res => {
						if (res.data.code == 1000) {}
					}).catch(err => {})
			},
			userTaskStep(taskStepId) { //首页添加健康豆
				let fdata = {
					userId: uni.getStorageSync(global.IS_DEV?'USER_DATA_BSY_T':'USER_DATA_BSY_Z').userId,
					userStepId: taskStepId,
					taskAppendix: ''
				}
				this.$api.put(global.apiUrls.userTaskStep, fdata)
					.then(res => {
						if (res.data.code == 1000) {
							let result = res.data.result;

						}
					}).catch(err => {})
			},
			descriptionAdd(e) {
				this.listArr.push({
					differentiate: 'system',
					askName: e,
				});
			},
			itemsa(e) {
				console.log(e, '484多选多选')
				// let ansValue4 = e.ansValue4.split(',')
				this.items = e
			},
			tapHint(e) {
				console.log(e)
				if (e.askId == this.askId &&
					this.listArr[this.listArr.length - 1].askName != e.guessAnswer &&
					this.listArr[this.listArr.length - 2].askName != e.guessAnswer &&
					this.listArr[this.listArr.length - 3].askName != e.guessAnswer) {
					this.listArr.push({
						differentiate: 'system',
						askName: e.guessAnswer
					});
					setTimeout(() => {
						uni.pageScrollTo({
							scrollTop: 99999999999,
							duration: 0
						});
					}, 200)
				}
			},
			handleTap(name) {
				this.$refs[name].show()
			},
			handleChange(e) {
				console.log('change::', e)
				if (e.dataset.name === 'picker10') {
					this.$set(this.value10, this.value10Active, e.value)
				}
			},
			handleConfirmS(e) { //小数点提交
				if (this.askName == '你通常每天有多少时间坐着或靠着？') {
					console.log(e.value, '7100000000000000000000')
					let ansValue = e.value;

					this.ansValue = ansValue.join('')
					this.ansValueV = ansValue[0] * 60 + ansValue[2]
					console.log(ansValue[0] * 60 + ansValue[2])
					// return
					userAnswerDetail(this)
				} else {
					this.askId = e.item[0].children[0].askId
					this.ansId = e.item[0].children[0].ansId;
					let ansValue = [],
						ansValueV = [];
					for (let i = 0; i < e.value.length; i++) {
						ansValue.push(e.value[i])
						if (i != e.value.length - 1) {
							if (e.value[i] == 'mm') {
								e.value[i] = ','
							}
							ansValueV.push(e.value[i])
						}
					}
					if(this.askName == '您最大的斑块大小是多少？长x厚(mm) '){
						console.log(ansValue,10644444444444)
						// ansValue.splice(3, 0, " x ")
						this.ansValue = ansValue[0]+'.'+ansValue[1]+ansValue[2] +' x '+ansValue[3]+'.'+ansValue[4]+ansValue[5]
						this.ansValueV = ansValue[0]+'.'+ansValue[1]+'mm x '+ansValue[3]+'.'+ansValue[4]
					}else{
						this.ansValue = ansValue.join('')
						this.ansValueV = ansValueV.join('')
					}

					userAnswerDetail(this)
				}
			},
			handleConfirm(e) {
				console.log(e)
				let t = this,
					answersArr = this.answersArr,
					askType = this.askType;
				if (askType == 5) { //生日
					this.ansValue = e.value
					this.ansValueV = e.value
				} else if (askType == 3) {
					t.ansId = e.item.ansId
					// t.ansValue = e.value
					t.ansValue = e.item.ansName
					this.ansValueV = e.item.ansName
				} else if (askType == 4) {
					t.ansValue = e.value
					t.ansValue = e.item.ansName
					this.ansValueV = e.item.ansName
				} else if (askType == 1) {
					t.ansValue = e.item[0].label + e.item[1].label
					this.ansValueV = e.item[0].label
				}
				// setTimeout(() => {
				userAnswerDetail(t)
				// }, 500);

			},
			handleCancel(e) {
				this.ansValue = '不知道'
				this.ansValueV = '不知道'
				userAnswerDetail(this)
				console.log('cancel::', e)
			},
			gendertap(e) {
				console.log(e);
				// if(e == 'cancel'){
				// }else{
				// }
				this.genderup = false
			},
			formSubmit(e) {
				let t = this;
				t.ansValue = e.detail.value.userInput;
				t.ansValueV = e.detail.value.userInput;
				userAnswerDetail(t)
			}
		}
	}
</script>

<style lang="scss">
	@import "./newBase.scss";

	.navbar-view {
		position: relative;
	}

	.sticky {
		width: 750rpx;
		height: 120rpx;
		background-color: #2979ff;
		color: #fff;
		padding: 24rpx;
	}

	.iphonexH {
		height: 140upx !important;
	}

	.hint {
		font-size: 28upx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #2EA7E0;
		line-height: 48upx;
	}

	.transmit {
		width: 100vw;
		height: 110upx;
		position: fixed;
		z-index: 3;
		bottom: 0;
		background: #fff;

		.sendBtn {
			width: 100upx;
			font-size: 24upx;
			float: right;
			margin: 20rpx 30rpx 0 0;
			padding: 0;
		}
	}

	.userSay {
		max-width: 500upx;
		min-width: 200upx;
		text-align: center;
		display: inline-block;
		padding: 21upx 19upx 30upx 23upx;
		border-radius: 10upx 10upx 0 10upx;
		box-sizing: border-box;
		font-size: 36upx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #4A4A4A;
		line-height: 60upx;
		background: #FFFFFF;
		position: relative;
		float: right;
		background: #2EA7E0;
	}

	.userSay::before {
		content: '';
		width: 0;
		height: 0;
		position: absolute;
		bottom: -24rpx;
		right: 0;
		border-top: 24upx solid #2EA7E0;
		border-left: 40upx solid transparent;
		// background: linear-gradient(112deg, #81C042 0%, #2EA7E0 100%);
	}

	.genderPopup {
		width: 750upx;
		height: 374upx;
		background: #fff;
		position: absolute;
		bottom: 0;
	}

	.genderView {
		height: 270rpx;
		line-height: 270rpx;
	}

	.whether {
		text-align: center;
	}

	.genderTitle {
		text-align: center;
	}

	.sendAudio {
		width: 52rpx;
		height: 52rpx;
		background: url('https://pics.leshiguang.com/vpage/2024/01/11/3184b7f4a5e54a8a917284f26fb1dee6.png')no-repeat;
		background-size: 52rpx 52rpx;
		margin: 27rpx 17rpx 0 20rpx;
	}

	.inputSend {
		width: 565rpx;
		height: 71rpx;
		background: #F5F5F5;
		border-radius: 12upx;
		border: 1upx solid #E2E1E2;
		margin-top: 17upx;
		padding: 0 20upx;
		box-sizing: border-box;
	}

	.expression {
		width: 52rpx;
		height: 52rpx;
		background: url(https://pics.leshiguang.com/vpage/2024/01/11/39ed490cbaa240fc93402b1b6d7e1f7a.png)no-repeat;
		background-size: 52rpx 52rpx;
		margin: 27rpx 21rpx 0 20rpx;
	}

	.moreBtn {
		width: 52rpx;
		height: 52rpx;
		background: url(https://pics.leshiguang.com/vpage/2024/01/11/6aab6ad1539c424e9e6e7cbd6cfc4ce7.png)no-repeat;
		background-size: 52rpx 52rpx;
		margin-top: 27rpx;
	}

	.step-view {
		width: 750upx;
		height: 92upx;
		display: flex;
		position: fixed;
		background: url(https://static.bsyjk.cn/health-pg/2E165323C8EE47EC902A95A24679A025.png)no-repeat;
		background-size: 100% 100%;
		font-size: 24upx;
		line-height: 92upx;
		color: #fff;
		z-index: 2;

		.step-left {
			padding-left: 20upx;
		}

		.step-step {
			width: 400upx;
			display: flex;

			.line-progress {
				width: 228upx;
				height: 18upx;
				padding: 2upx 20upx;
			}
		}

		.step-right {}
	}
</style>
